#ifndef GENERATOROBJECT_H
#define GENERATOROBJECT_H

#include <QObject>
#include "generator_global.h"
#include <QSerialPort>
#include <QHash>

class GeneratorObject : public QObject
{
    Q_OBJECT
public:
    explicit GeneratorObject(QObject *parent = 0);
    ~GeneratorObject() { serialPort->close(); }

    bool isSerialPortOpened() const { return serialPort->isOpen(); }
    QString getName() const { return name; }
    QString getPortName() const { return portName; }

signals:
    void deviceStatus(GeneratorState state, const QString &msg = QString());

public slots:
    void onOpenSerialPort();

    virtual void onPowerOn() {}
    virtual void onPowerOff() {}

    virtual void onSetRFR() {}
    virtual void onSetMsMode(bool) {}
    virtual void onSetMxMode(bool) {}
    virtual void onSetFCL(bool) {}
    virtual void onSetFCS(bool) {}

    virtual void onKvInc() {}
    virtual void onKvDec() {}
    virtual void onKvValue(const double &) {}

    virtual void onMaInc() {}
    virtual void onMaDec() {}
    virtual void onMaValue(const double &) {}

    virtual void onMsInc() {}
    virtual void onMsDec() {}
    virtual void onMsValue(const double &) {}

    virtual void onMxInc() {}
    virtual void onMxDec() {}
    virtual void onMxValue(const double &) {}

    virtual void onSetRFF() {}
    virtual void onFKvInc() {}
    virtual void onFKvDec() {}
    virtual void onFMaInc() {}
    virtual void onFMaDec() {}
    virtual void onSetIBS() {}
    virtual void onResetFSec() {}

    virtual void onSetAEC() {}
    virtual void onDenInc() {}
    virtual void onDenDec() {}
    virtual void onSetFIL() {}
    virtual void onSetFIC() {}
    virtual void onSetFIR() {}

protected slots:
    void onSerialPortReadReady() { serialBuffer += serialPort->readAll(); analysisData(); }

protected:
    virtual void analysisData() = 0;

    QString name;
    QString portName;
    QHash<int, QString> errHash;
    QSerialPort *serialPort;
    QByteArray serialBuffer;
};

#endif // GENERATOROBJECT_H
